package com.czk.ssacharmemory.controller;

import jakarta.annotation.Resource;
import org.springframework.ai.chat.client.ChatClient;
import org.springframework.ai.chat.model.ChatModel;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
import reactor.core.publisher.Flux;

import static org.springframework.ai.chat.memory.ChatMemory.CONVERSATION_ID;

/**
 * @Author: chenzhangkun
 * @CreateTime: 2025-10-19
 * @Description:
 * @Version: 1.0
 */
@RestController
public class ChatMemoryController {
    @Resource(name = "deepseekChatClient")
    private ChatClient deepeekChatClient;
    @Resource(name = "qwenChatClient")
    private ChatClient qwenChatClient;
    @Resource(name = "deepseek")
    private ChatModel deepeekChatModel;
    @Resource(name = "qwen")
    private ChatModel qwenChatModel;

    /**
     * 对话存储的测试
     *
     * @param msg    消息
     * @param userId 用户id
     * @return
     */
    @GetMapping(value = "/chatmemory/chat")
    public Flux<String> chat(String msg, String userId) {
        return qwenChatClient.prompt(msg)
                .advisors(ad -> {
                    // 指定对话id 指定每个用户的对话存储,这里指定为用户id
                    ad.param(CONVERSATION_ID, userId);
                }).stream().content();
    }
}
